﻿using System;
using System.Data.Common;
using System.Collections.Generic;
using Sinacor.Infra.Service.Data;
using Sinacor.Infra.Service.Security.Authorization;

namespace Sinacor.Servico.Bovespa.Contabil.ResourceAccess
{
    /// <summary>
    /// ResourceAccess Class - GrupoContabil
    /// </summary>
    public class GrupoContabil : BaseResourceAccess
    {
        #region Construtor

        /// <summary>
        /// Construtor
        /// </summary>
        public GrupoContabil() : base(AuthorizationContext.Current.CompanyId) { }

        #endregion

        #region Métodos Públicos

        #region ConsultarGruposContabeis

        /// <summary>
        /// Serviço irá Consultar uma lista de Grupos Contábeis
        /// </summary>
        /// <returns>Lista de objetos do tipo ConsultarGruposContabeis</returns>
        public List<BusinessEntity.GrupoContabil> ConsultarGruposContabeis()
        {
            String sql = @"SELECT CD_GRUP_CONT Codigo,
                                  DS_GRUP_CONT Descricao
                             FROM TSCGRUCON 
                         ORDER BY DS_GRUP_CONT";

            List<BusinessEntity.GrupoContabil> response = new List<BusinessEntity.GrupoContabil>();

            using (DbCommand dbCommand = this.DataBase.GetSqlStringCommand(sql))
            {
                response = this.FindAll<BusinessEntity.GrupoContabil>(dbCommand,
                    reader =>
                    {
                        BusinessEntity.GrupoContabil entity = new BusinessEntity.GrupoContabil();

                        entity.Codigo = reader.GetValue<Int32>("Codigo");
                        entity.Descricao = reader.GetValue<String>("Descricao");

                        return entity;
                    });

                return response;
            }
        }

        #endregion

        #endregion
    }
}
